package ua.lviv.franko.solvers.stressanalysis.twoDimention.fem;

import java.util.ArrayList;

import ua.lviv.franko.integration.IFEMFunction2D;
import ua.lviv.franko.integration.IFunction2D;
import ua.lviv.franko.triangulation.SaveStructures.Node;

/**
 * 
 * @author marko.bekhta
 *         https://docs.google.com/viewer?a=v&q=cache:iNdg28w6oJAJ:www
 *         .mae.ufl.edu
 *         /haftka/finite-element/Lecture17.pdf+isoparametric+element
 *         &hl=uk&gl=ua
 *         &pid=bl&srcid=ADGEEShnXI0eKhivNLx9iMmladIWN6y8x1aaXllJkfDX6OPmn
 *         -bgxK04O-vDbg0-PcGdk_gEIDSouza-JA1MAN-sEH7T2n562NKhtPqmG-Df0yX3-
 *         qT_aUTOwMEjOo2clzEWWexIQi0u&sig=AHIEtbR5AT50usvWqg23iXmMRCUNZCbung
 */
public class BilinearIsoparamerticQuadrilateral extends AbstractIsoparametricQuadrilateral {

	public BilinearIsoparamerticQuadrilateral(double k1, double k2, double k3, IFunction2D f1Function, IFunction2D f2Function, final Node A, final Node B, final Node C,
			final Node D) {
		super(k1, k2, k3, f1Function, f2Function);

		nodes = new ArrayList<Node>();
		nodes.add(A);
		nodes.add(B);
		nodes.add(C);
		nodes.add(D);

		pos = new ArrayList<Integer>();
		pos.add(A.Number);
		pos.add(B.Number);
		pos.add(C.Number);
		pos.add(D.Number);

		// N1 (A)
		IFEMFunction2D Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1 - x) * (1 - y) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return -(1 - y) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return -(1 - x) / 4.0;
			}

			@Override
			public double getXi() {
				return -1;
			}

			@Override
			public double getYi() {
				return -1;
			}
			@Override
			public Node getNode() {
				return A;
			}
		};

		baseFunctions.add(Ni);

		// N2 (B)
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1 + x) * (1 - y) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return (1 - y) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return -(1 + x) / 4.0;
			}

			@Override
			public double getXi() {
				return 1;
			}

			@Override
			public double getYi() {
				return -1;
			}
			@Override
			public Node getNode() {
				return B;
			}
		};

		baseFunctions.add(Ni);

		// N3 (C)
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1 + x) * (1 + y) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return (1 + y) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return (1 + x) / 4.0;
			}

			@Override
			public double getXi() {
				return 1;
			}

			@Override
			public double getYi() {
				return 1;
			}
			@Override
			public Node getNode() {
				return C;
			}
		};

		baseFunctions.add(Ni);

		// N4 (D)
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1 - x) * (1 + y) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return -(1 + y) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return (1 - x) / 4.0;
			}

			@Override
			public double getXi() {
				return -1;
			}

			@Override
			public double getYi() {
				return 1;
			}
			@Override
			public Node getNode() {
				return D;
			}
		};

		baseFunctions.add(Ni);

	}

	@Override
	public double calculateSigma11(double x, double y, double[] vals) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public double calculateSigma12(double x, double y, double[] vals) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public double calculateSigma22(double x, double y, double[] vals) {
		// TODO Auto-generated method stub
		return 0;
	}

}
